Xbasic

Array push Method

Syntax

V <array>.push(value as A)

Arguments

valueAny Type

The value to append to the end of the array.

Description

Adds a new item to the array.

Discussion

The array push() method adds the specified value to the end of the array as a new entry. Using this method is the equivalent of calling append() to add one entry to the array and then setting the value of the element of the array using the returned index.

Example

dim arr[0] as c
arr.push("hello")
arr.push("world")
? arr
= [1] = "hello"
[2] = "world"
 

'using a property array
dim arrp[0] as p
 

'push objected defined using JSON syntax onto the array
arrp.push({"text":"hello"})
arrp.push({"text":"world"})
? arrp.size()
= 2
? arrp[1].text
= "hello"
? arrp[2].text
= "world"

See Also